package com.mmf.ancientcostume.service.home;

import com.mmf.ancientcostume.common.utils.service.RetrofitUtil;
import com.mmf.ancientcostume.common.utils.service.SecretConstant;
import com.mmf.ancientcostume.model.Comment;
import com.mmf.ancientcostume.model.GoodsDetail;
import com.mmf.ancientcostume.model.GoodsDetailAndImg;
import com.mmf.ancientcostume.model.LawyerInfo;
import com.mmf.ancientcostume.model.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import rx.Observable;

/**
 * Created by MMF
 * date 2016/9/26
 * Description:
 */
public class HomeService extends RetrofitUtil {
    private static HomeServiceApi homeService;

    public static HomeServiceApi getService() {
        if (homeService == null) {
            homeService = getRetrofit(SecretConstant.API_HOST).create(HomeServiceApi.class);
        }
        return homeService;
    }

    public Observable<List<LawyerInfo>> getLawyer() {
        return getService().getLawyer("json", 0, 10, "福州", "6f940a4a81649f3b6d30e47cdd37a5ad")
                .compose(this.<List<LawyerInfo>>applySchedulers());
//        success(lawyerInfoList);
    }

    public Observable<List<User>> list() {
        Map<String, Object> params = new HashMap<>();
        params.put("mao", "mao");
        params.put("passwd", "mao");
        return getService().list(params)
                .compose(this.<List<User>>applySchedulers());
//        success(lawyerInfoList);
//        return getService().getInfo("nQS647KWkRaA8LkIXvCKwfuIcrbl9sHC", "157287", "3C:B5:09:43:AB:5C:FB:F1:A1:B8:DB:6A:CD:F2:6D:6D:76:74:70:26;com.mmf.framework", loc)
//                .compose(this.<List<PositionInfo>>applySchedulers());
    }

    public Observable<String> insertDetail(Map<String, RequestBody> bodyMap, Map<String, Object> info) {
        return getService().insertDetail(info, bodyMap)
                .compose(this.<String>applySchedulers());
    }

    public Observable<GoodsDetailAndImg> getGoodsDetail(int id, int userId) {
        return getService().getGoodsDetail(id, userId)
                .compose(this.<GoodsDetailAndImg>applySchedulers());
    }

    public Observable<List<GoodsDetail>> getGoodsList(int pageNo, int pageSize) {
        return getService().getGoodsList(pageNo, pageSize)
                .compose(this.<List<GoodsDetail>>applySchedulers());
    }

    public Observable<String> collect(int goodsId, int userId) {
        return getService().collect(goodsId, userId)
                .compose(this.<String>applySchedulers());
    }

    public Observable<String> cancelCollect(int goodsId, int userId) {
        return getService().cancelCollect(goodsId, userId)
                .compose(this.<String>applySchedulers());
    }

    public Observable<List<GoodsDetail>> getCollectList(int pageNo, int pageSize, int userId) {
        return getService().getCollectList(pageNo, pageSize, userId)
                .compose(this.<List<GoodsDetail>>applySchedulers());
    }

    public Observable<String> insertComment(Map<String, Object> params, Map<String, RequestBody> bodyMap) {
        return getService().insertComment(params, bodyMap)
                .compose(this.<String>applySchedulers());
    }

    public Observable<String> deleteComment(int id) {
        return getService().deleteComment(id)
                .compose(this.<String>applySchedulers());
    }

    public Observable<Comment> updateComment(Map<String, Object> params, Map<String, RequestBody> bodyMap) {
        return getService().updateComment(params, bodyMap)
                .compose(this.<Comment>applySchedulers());
    }

    public Observable<Comment> findComment(int id) {
        return getService().findComment(id)
                .compose(this.<Comment>applySchedulers());
    }

    public Observable<List<Comment>> getCommentList(Map<String, Object> params) {
        return getService().getCommentList(params)
                .compose(this.<List<Comment>>applySchedulers());
    }

}
